$(document).ready(function(e) {
	// validate signup form on keyup and submit
    $("input.required").change(function(){
        checkvalidate(this);
    });
    $("input.required").blur(function(){
        checkvalidate(this);
        var check = $(this).attr("check");
        if(check != undefined){
            if(!checkkey(check,$(this).val())){
                $(this).parent().removeClass("has-success").addClass("has-error");
            }else{
                $(this).parent().removeClass("has-error").addClass("has-success");
            }
        }
    });

    $('input#rpassword').blur(function(){
        if($("input#rpassword").val() != $("input#NewPassword").val()){
            $(this).parent().removeClass("has-success").addClass("has-error");
        }else{
            $(this).parent().removeClass("has-error").addClass("has-success");
        }    
    });
});

function checkvalidate(obj){
    var parent = $(obj).parent();
    if($(obj).val() == ''){
        $(parent).removeClass("has-success").addClass("has-error");
    }else{
        $(parent).removeClass("has-error").addClass("has-success");
    }
}

function doimatkhau(){
	var fg=true;
	$("#boxDoiMatKhau input.required").each(function () {
        if($(this).val() == ''){
            fg=false;
        }
    });

    if(!fg)
        return fg;
    
	var matkhau = $("#txtMatKhauHienTai").val();
	var matkhaumoi = $("#NewPassword").val();

	$.ajax({
		type: "POST",
  		url: 'ajax.aspx',
  		data: { M:'DoiMatKhau', MatKhau: matkhau, MatKhauMoi: matkhaumoi },
  		success: function (data) {
  		    data = $.parseJSON(data);
  		    if (data.Status == 'Success') {
  		        alert("Đổi mật khẩu thành công!");
  		        $('#boxDoiMatKhau').modal('hide');
  		    }
  		    else {
  		        alert(data.Mess);
  		    }
		}
	});
	return false;
}